//
//  HeadView.m
//  PTravel
//
//  Created by dllo on 15/11/20.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "HeadSliderView.h"

@implementation HeadSliderView

- (void)dealloc
{
    [_slider release];
    [_freeButton release];
    [_locationBUtton release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changColor) name:@"night" object:nil];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)changColor
{
    self.backgroundColor = CELLCOLOR;
    [self.locationBUtton setTitleColor:TEXTCOLOR forState:UIControlStateNormal];
    self.locationBUtton.backgroundColor = CELLCOLOR;
    self.freeButton.backgroundColor = CELLCOLOR;
}

- (void)createSubViews
{
    
    self.freeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.freeButton.frame = CGRectMake(0, 0, BOUNDS.size.width/2, 30);
    [self.freeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.freeButton setTitle:@"超值自由行" forState:UIControlStateNormal];
    [self.freeButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [self.freeButton addTarget:self action:@selector(freeButtonActiuon) forControlEvents:UIControlEventTouchUpInside];
    self.freeButton.backgroundColor = CELLCOLOR;
    [self addSubview:self.freeButton];
    [_freeButton release];
    
    self.locationBUtton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.locationBUtton.frame = CGRectMake(BOUNDS.size.width/2, 0, BOUNDS.size.width/2, 30);
    [self.locationBUtton setTitle:@"精彩当地游" forState:UIControlStateNormal];
    [self.locationBUtton setTitleColor:TEXTCOLOR forState:UIControlStateNormal];
    [self.locationBUtton addTarget:self action:@selector(locationBUttonActiuon) forControlEvents:UIControlEventTouchUpInside];
    self.locationBUtton.backgroundColor = CELLCOLOR;
    [self addSubview:self.locationBUtton];
    [_locationBUtton release];
    
    self.slider = [[UIView alloc] initWithFrame:CGRectMake(BOUNDS.size.width/2-140, 30, 90, 2)];
    [self addSubview:self.slider];
    [_slider release];
    
    self.layer.borderColor = [UIColor blackColor].CGColor;
    self.layer.masksToBounds = YES;
}

- (void)freeButtonActiuon
{
    [UIView animateWithDuration:0.5 animations:^{
        self.slider.frame = CGRectMake(BOUNDS.size.width/2-140, 30, 90, 2);
        [self.freeButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [self.locationBUtton setTitleColor:TEXTCOLOR forState:UIControlStateNormal];
    }];
    self.isFree = YES;
    self.free = [[TotalFreeViewController alloc] init];
    [self.free create];
    
    
}

- (void)locationBUttonActiuon
{
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.locationBUtton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [self.freeButton setTitleColor:TEXTCOLOR forState:UIControlStateNormal];
        self.slider.frame = CGRectMake(BOUNDS.size.width-140, 30, 90, 2);
    }];
    self.isFree = NO;
    self.free = [[TotalFreeViewController alloc] init];
    [self.free create];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
